/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_CORE_API_COLLECTIONS_CTREE_HPP
#define	_CUBEFS_CORE_API_COLLECTIONS_CTREE_HPP

#include <cubefs/api/models/ctree.hpp>
#include <cubefs/core/api/models/dyn_vector.hpp>

#define CUBEFS_SOURCE "cubefs/core/api/models/ctree.hpp:" CUBEFS_AT

namespace cubefs    {
namespace api       {

template <typename Interface>
class CTreeLabelImplT: public DataImplT<Interface> {
	 typedef CTreeLabelImplT<Interface>		Me;
	 typedef DataImplT<Interface> 			Base;
public:
    CUBEFS_DECLARE_REFLECTION;
};

template <typename Interface>
Type* CTreeLabelImplT<Interface>::type_ 	= NULL;
typedef CTreeLabelImplT<CTreeLabel> 		CTreeLabelImpl;

CUBEFS_DEFINE_PARAMETER_TYPE(CTreeLabel);


template <typename Interface>
class CTreePathSetImplT: public DataImplT<Interface> {
	typedef CTreePathSetImplT<Interface>	Me;
	typedef DataImplT<Interface> 			Base;

public:
    CUBEFS_DECLARE_REFLECTION;
};

template <typename Interface>
Type* CTreePathSetImplT<Interface>::type_ 	= NULL;
typedef CTreePathSetImplT<CTreePathSet>		CTreePathSetImpl;

CUBEFS_DEFINE_PARAMETER_TYPE(CTreePathSet);


template <typename Interface>
class CTreeIteratorImplT: public DataIteratorImplT<Interface> {
	typedef CTreeIteratorImplT<Interface> 	Me;
	typedef DataIteratorImplT<Interface>	Base;
public:

    virtual void Root()                         = 0;
    virtual bool Parent()                       = 0;

    virtual bool NextChild()                    = 0;
    virtual bool PrevChild()                    = 0;

    virtual bool NextSibling()                  = 0;
    virtual bool PrevSibling()                  = 0;

    virtual bool Child(CTreeLabel* label)       = 0;
    virtual bool Child(BigInt index)            = 0;

    virtual BigInt GetChildIndex()              = 0;
    virtual BigInt GetSubtreeSize()             = 0;
    virtual BigInt GetChildrenCount()           = 0;

    virtual void GetLabel(CTreeLabel* label)    = 0;
    virtual bool GetNodeData(Typed* holder)     = 0;

    virtual void Insert(CTreePathSet* paths)    = 0;
    virtual bool Remove(CTreePathSet* paths)    = 0;

    CUBEFS_DECLARE_REFLECTION;
};

template <typename Interface>
Type* CTreeIteratorImplT<Interface>::type_		= NULL;
typedef CTreeIteratorImplT<CTreeIterator>		CTreeIteratorImpl;



template <typename Interface>
class CTreeImplT: public DynVectorImplT<Interface> {
	typedef CTreeImplT<Interface> 		Me;
	typedef DynVectorImplT<Interface>	Base;

public:
    virtual Int GetCTreeType()                                      = 0;
    virtual CTreeIterator* GetRoot()                                = 0;

    virtual CTreePathSet* CreateSimplePath(Int length)              = 0;
    virtual Typed* CreateNodeDataHolder()                           = 0;
    virtual CTreeLabel* CreateLabelHolder()                         = 0;

    CUBEFS_DECLARE_REFLECTION;
};

template <typename Interface>
Type* CTreeImplT<Interface>::type_		= NULL;
typedef CTreeImplT<CTree>				CTreeImpl;





}
}

#undef CUBEFS_SOURCE

#endif
